<script type="text/javascript">
$(function(){
	var pg = App.deploy.planIndex.ui, pp = pg.params || {},
		mainGd = pg.seek('mainGd');
	var w = mac.wait('Loading');
	// 自动化部署应用boar-deploy-agent的id
	var svcAppId = '9483859e5acbaa3a015acbb59d2c0001';
		
	mainGd.mac('grid',{
		cols:[{
			field: 'name', title: '计划名称', width: 240, sort: true,
			 render: function(r, tr){
				return $('<span class="a"></span>').click(function(){
					App.open({
						title: '部署计划基本信息',
						ctx: 'deploy',
						action: 'planEdit',
						model: true,
						params: r
					}, function(){
						App.show({
							ctx: 'deploy',
							action: 'planItem',
							params: r
						}, $.noop, pg.parent());
					});
				}).append(r.name);
			} 
		},{
			field: 'code', title : '计划编号', width: 80,sort: true,
		},{
			field: 'catalog', title : '部署流程', width: 80,
			render: function(r){
				var f = $('<form method="post" action="/soagov/flow/edit.do" target="_blank"></form>');
				f.append('<input type="hidden" name="id" value="' + r.id + '" />');
				f.append('<input type="hidden" name="code" value="' + r.code + '" />');
				f.append('<input type="hidden" name="name" value="' + r.name + '" />');
				f.append('<input type="hidden" name="type" value="1" />');
				f.append('<input type="hidden" name="catalog" value="deploy" />');
				f.append('<input type="hidden" name="appId" value="'+ svcAppId +'" />');
				f.append('<input type="hidden" name="url" value="/soagov/#flow/edit?catalog=deploy&id='
					+ r.id + '&code=' + r.code + '" />');
				f.append($('<span class="a">编辑流程</span>').click(function(){
					f[0].submit();
				}));
				return f;
			}
		},{
			field: 'onlineTime', title : '计划上线时间', width: 120,sort: true,
		},{
			field: 'packIp', title : '打包服务器IP', width: 120
		},{
			field: 'packPort', title : '打包服务器端口', width: 120
		},{
			field: 'memo', title : '备忘录', width: 170
		},{
			field: 'op', title : '操作', width: 100,
			render: function(r){
				var d = $('<div></div>')
				var a = $('<span class="a">导出</span>');
				a.click(function(){
					var w = mac.wait('Loading');
					$.post(App.deploy.ctx + '/plan/export.do', {
						id: r.id
					},function(data){
						w.close();
						var ro = mac.eval(data);
						App.open({
							ctx: 'deploy',
							title:'部署计划导出',
							action: 'planExport',
							model: true,
							params: ro
						});
					});
				}).appendTo(d);;
				d.append('&nbsp;');
				$('<span class="a">删除</span>').click(function(){
					mac.confirm('确定要删除 ' + r.name + ' 计划？', function () {
						$.post(App.deploy.ctx + '/plan/delete.do', {
							id: r.id
						},function(){
							console.log('in delete callback');
							mainGd.load()
						});
					});
					
				}).appendTo(d);
				return d;
			}
		}] ,
	 	loader: {
			url: App.deploy.ctx + '/plan/list.do',
			params: { 
				projId: pp.projId,
				pageNo: 1, 
				pageSize: 10 
			},
			autoLoad: true
		},
		afterLoad: function(dd, po){
			w.close();
		},
		pagerLength: 10
	});
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13)
			mainGd.load({ key : $(this).val() });
	});
	pg.seek('create').click(function(){
		App.open({
			title: '部署计划基本信息',
			ctx: 'deploy',
			action: 'planEdit',
			model: true,
			params: pp
		}, function(){
			mainGd.load();
		});
	});
	function adjust(){
		var p = pg.parent(), h = p.height();
		pg.height(h-24);
		pg.children('.body').height(h-80);
		mainGd.adjust();
	}
	$(window).resize(adjust);
	adjust();
})
</script>
<div class="head">
	<button name="create">创建</button>
	<button name="import">导入</button>
	<input name="key" class="fr" placeholder="查找" />
	<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="body">
	<div class="grid" name="mainGd"></div>
</div>